import com.opensymphony.module.sitemesh.Page;
import com.opensymphony.module.sitemesh.HTMLPage;
import com.opensymphony.module.sitemesh.RequestConstants;
import com.opensymphony.module.sitemesh.util.OutputConverter;

class SiteMeshDecorator implements RequestConstants {

	def getOut = { resp ->
		return OutputConverter.getWriter(resp.writer);
	}
	
	def getPage = { request ->
		Page p = (Page) request[PAGE];
		return p;
	}
	
	def writeBody = { req, resp ->
		getPage(request).writeBody(getOut(resp));
	}
	
	def writeHead = { req, resp ->
		HTMLPage htmlPage = (HTMLPage)getPage(request);
		htmlPage.writeHead(getOut(resp));
	}
	
}

logger.log.info "Initializing siteMesh plugin"

def decorator = new SiteMeshDecorator()

// add new variables in the binding
binding {
	// an instance of a class of a third-party JAR
	siteMeshDecorator = decorator
}

logger.log.info "siteMesh plugin successfully initialized"